import UsersApi from "../../api/users.js";
import Base from '../base.js';
export default class extends Base {
  render() {
      this.$el.html(`
    <div id="block1" class="w3lvide-content" data-vide-options="position: 0% 50%">
      <!-- 内容 -->
      <div class="workinghny-form-grid">
          <div class="main-hotair">
              <div class="content-wthree">
                  <!-- 注册两字 -->
                  <h1 style="font-size: 40px;">用户注册</h1>
                  <form action="#" method="post">
                      <!-- 输入框 -->
                      <input type="text" class="username" name="username" placeholder="请输入注册账号" required="请输入注册账号" autofocus>
                      <input type="password" class="password" name="password" placeholder="请输入注册密码" required="请输入注册密码"
                          autofocus>
                          <!-- 按钮 -->
                      <button class="reg-btn" name="reg-btn"type="button">确定注册</button>
                  </form>
                  <a href="#/login" id="topRight">
                  <span class="fa" name="reg-btn">管理登录</span>
                  </a>
                  <!-- 附加信息 -->
                  <p class="continue"><span>Four groups of production</span></p>
              </div>
          </div>
          <!-- 底部友情链接板块 -->
          <div class="copyright text-center">
              <p class="copy-footer-29">© 2021 友情链接 | <a href="https://baidu.com">百度</a></p>
          </div>
      </div>
  </div>
  `);
      this.$usernameEle = $("input[name=username]"); //获取输入用户名
      this.$passwordEle = $("input[name=password]");//获取输入密码
      this.$regBtn = $("button[name=reg-btn]"); //获取注册按钮
  }
  async regHandle() {
    
      const username = this.$usernameEle.val(); //获取输入的值
      const password = this.$passwordEle.val();
      const data=await UsersApi.reg({username,password}); 
      if (data) {
        // adminsApi.setToken(token);
        layer.msg("注册成功，即将跳转登录页面");
        location.hash = "#/usersLogin";
        return;
      };
          // 登录失败弹窗
    layer.msg("注册失败，账户已存在，5秒自动关闭", {
        time: 5*1000
        ,success: function(layero, index){
          var timeNum = this.time/1000, setText = function(start){
            layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
          };
          setText(!0);
          this.timer = setInterval(setText, 1000);
          if(timeNum <= 0) clearInterval(this.timer);
        }
        ,end: function(){
          clearInterval(this.timer);
        },
        btn: ['确定','取消','返回']
      });  
  }
  handle() {
      this.$regBtn.on("click", this.regHandle.bind(this));
  }
};
// console.log(Base.data);
// module.exports={data}；;